package dcutils.rpg.stats;

// Import Java JDK Classes
import java.util.LinkedHashMap;
import java.util.List;

/**
 * This stats class may represent a character&apos;s collection of stats.<br/>
 * @author dca
 */
public class Stats extends LinkedHashMap<String, Stat> {
   /** Unique identifier for serialization. */
   private static final long serialVersionUID = -5861504747560033654L;

   public Stats() {
      super(0);
   } // END constructor

   public Stats(List<Stat> stats) {
      if(null != stats) {
         for(Stat stat : stats) {
            put(stat.getName(), stat);
         } // END loop
      } // END if
   } // END constructor

   @Override
   public String toString() {
      final StringBuffer buffer = new StringBuffer(512 * keySet().size());

      for(String statName : keySet()) {
         if(!buffer.toString().isEmpty()) buffer.append(String.format("%n"));
         buffer.append(String.format("%s: %s", statName, get(statName).cur()));
      } // END loop

      return buffer.toString();
   } // END toString
  
   @Override
   public boolean equals(Object obj) {
      if(null == obj) {
         return false;
      } else if(obj instanceof Stats) {
         Stats stats = (Stats)obj;

         return super.equals(stats);
      } else {
         return false;
      } // END if/else
   } // END equals

   @Override
   public int hashCode() {
      int hashCode = 101;
      hashCode = (11 * hashCode) + super.hashCode();
      return hashCode;
   } // END hashCode
} // END class Stats
